//
//  LoginViewController.m
//  HomeDelivery
//
//  Created by apple on 16/7/21.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "LoginViewController.h"
#import "PhoneCodeLoginView.h"
#import "AccountLoginView.h"
#import "ForgetPassWordViewController.h"
@interface LoginViewController ()
{
    CGFloat btnWidth;
    NSInteger _selectedTag;
}
@property(nonatomic,strong)UIScrollView *scrollView;
@property(nonatomic,strong)UIView *lineView;
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"登录";
    btnWidth=WIDTH/2.0;
    _selectedTag=10;
    self.view.backgroundColor=GRAYCOLOR;
    [self setUpSegmentCtlBtn];
    [self.view addSubview:self.lineView];
    [self setUpTwoView];
 
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(pushToForgetPsw) name:@"pushToForgetPsw" object:nil];
}

-(void)pushToForgetPsw
{
    ForgetPassWordViewController *forget=[[ForgetPassWordViewController alloc]init];

    [self.navigationController pushViewController:forget animated:YES];
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
#pragma mark--线条
-(UIView *)lineView
{
    if (!_lineView) {
        _lineView=[[UIView alloc]initWithFrame:CGRectMake(0, 64+49, btnWidth, 2)];
        _lineView.backgroundColor=ORANGE;
    }
    return _lineView;
}
#pragma mark--选择条控件
-(void)setUpSegmentCtlBtn
{
    for (int i=0; i<2; i++) {
        UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(i*btnWidth, 64, btnWidth, 50)];
        [btn setTitle:@[@"账号登录",@"手机验证码登录"][i] forState:UIControlStateNormal];
        btn.backgroundColor=LIGHTGRAY;
        [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        btn.tag=(i+1)*10;
        btn.titleLabel.font=[UIFont systemFontOfSize:15];
        [btn addTarget:self action:@selector(clickOnBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
    
}
-(void)clickOnBtn:(UIButton *)btn
{
    UIButton *selecBtn=[self.view viewWithTag:_selectedTag];
    [selecBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:ORANGE forState:UIControlStateNormal];
    [UIView animateWithDuration:0.1 animations:^{
        CGRect rect=_lineView.frame;
        rect.origin.x=btn.frame.origin.x;
        _lineView.frame=rect;
    }];
    if (btn.tag==10) {
        [self.scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
    }else
    {
        [self.scrollView setContentOffset:CGPointMake(WIDTH, 0) animated:NO];

    }
    [self.scrollView endEditing:YES];
       _selectedTag=btn.tag;
    
}
#pragma mark--滚动图
-(UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,64+50.5, WIDTH, HEIGHT-64-50)];
        _scrollView.pagingEnabled=YES;
        _scrollView.scrollEnabled=NO;
        _scrollView.backgroundColor=LIGHTGRAY;
        _scrollView.showsVerticalScrollIndicator=NO;
        _scrollView.showsHorizontalScrollIndicator=NO;
        _scrollView.contentSize=CGSizeMake(WIDTH*2, HEIGHT
                                           -64);
       [self.view addSubview:self.scrollView];
    }
    return _scrollView;
}

#pragma mark--两种登录视图
-(void)setUpTwoView
{
    PhoneCodeLoginView *phoneCode=[[PhoneCodeLoginView alloc]initWithFrame:CGRectMake(WIDTH, 0, WIDTH, CGRectGetHeight(self.scrollView.frame))];
    phoneCode.backgroundColor=LIGHTGRAY;
    [self.scrollView addSubview:phoneCode];
    
    AccountLoginView *accountLogin=[[AccountLoginView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, CGRectGetHeight(self.scrollView.frame))];
    accountLogin.backgroundColor=LIGHTGRAY;
    [self.scrollView addSubview:accountLogin];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
